
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using Andromeda.Global.Business;
using Andromeda.Global.Data.Db;
using Andromeda.Global.Common;
using ForgeIt.Dal.dbo.Validator;

  
namespace ForgeIt.Dal.dbo.Stub
{
	internal abstract class DBLicenseStub : dboSchema
	{
		#region private fields

		/// <summary>
		/// (fieldname, datatype, ischangeable(!isidentity), isinsertable(!isidentity), isforeignkey, foreigntable
		/// </summary>

		protected readonly DbField foIdLicense = new DbField("IdLicense", DbType.Int32, true, true, false, false, false, "");

		protected readonly DbField foIdApplication = new DbField("IdApplication", DbType.Int32, false, false, true, true, true, "Application");

		protected readonly DbField foIdCustomer = new DbField("IdCustomer", DbType.Int32, false, false, true, true, true, "Customer");

		protected readonly DbField foIdTransaction = new DbField("IdTransaction", DbType.Int32, false, false, true, true, false, "");

		protected readonly DbField foLicenseType = new DbField("LicenseType", DbType.Int32, false, false, true, true, false, "");

		protected readonly DbField foLicenseStatus = new DbField("LicenseStatus", DbType.Int32, false, false, true, true, false, "");

		protected readonly DbField foLicenseData = new DbField("LicenseData", DbType.Binary, false, false, true, true, false, "");

		protected readonly DbField foLicenseExpiryDate = new DbField("LicenseExpiryDate", DbType.DateTime, false, false, true, true, false, "");

  
        #region local cache - Foreign Keys

        protected DBApplication localIdApplication;
  

        protected DBCustomer localIdCustomer;
  

        #endregion local cache - Foreign Keys


        #endregion private fields

        #region constructors

        protected DBLicenseStub()
		{
		}

		protected DBLicenseStub(bool ignorethis, int foIdTransaction, int foLicenseType, int foLicenseStatus, byte[] foLicenseData, System.DateTime foLicenseExpiryDate, Int32 foIdApplication, Int32 foIdCustomer)
		{

			this.foIdTransaction.Value = foIdTransaction;

			this.foLicenseType.Value = foLicenseType;

			this.foLicenseStatus.Value = foLicenseStatus;

			this.foLicenseData.Value = foLicenseData;

			this.foLicenseExpiryDate.Value = foLicenseExpiryDate;

			this.foIdApplication.Value = foIdApplication;

			this.foIdCustomer.Value = foIdCustomer;

		}
	
		#endregion constructors
    
		#region public properties
		
		public override DbConnector CleanEntity
		{
			get { return new DBLicense(); }
		}


		public int IdLicense
		{
			get { return ObjectConverter.ToInt32(foIdLicense.Value); }
		}

		public int IdApplication
		{
			get { return ObjectConverter.ToInt32(foIdApplication.Value); }
			set { foIdApplication.Value = value; }
		}

		public int IdCustomer
		{
			get { return ObjectConverter.ToInt32(foIdCustomer.Value); }
			set { foIdCustomer.Value = value; }
		}

		public int IdTransaction
		{
			get { return ObjectConverter.ToInt32(foIdTransaction.Value); }
			set { foIdTransaction.Value = value; }
		}

		public int LicenseType
		{
			get { return ObjectConverter.ToInt32(foLicenseType.Value); }
			set { foLicenseType.Value = value; }
		}

		public int LicenseStatus
		{
			get { return ObjectConverter.ToInt32(foLicenseStatus.Value); }
			set { foLicenseStatus.Value = value; }
		}

		public byte[] LicenseData
		{
			get { return ObjectConverter.ToByteArray(foLicenseData.Value); }
			set { foLicenseData.Value = value; }
		}

		public System.DateTime LicenseExpiryDate
		{
			get { return ObjectConverter.ToDateTime(foLicenseExpiryDate.Value); }
			set { foLicenseExpiryDate.Value = value; }
		}

  
		public override string TableName
		{
			get { return "License"; }
		}



        #region Foreign Keys
      
        /// <summary>
        /// Getter method for Object encapsulated view of foreign key
        /// </summary>
        public virtual DBApplication GetFK_IdApplication()
        {
          return localIdApplication ?? (localIdApplication = DBApplication.GetEntity(IdApplication));
        }
        /// <summary>
        /// Setter method for Object encapsulated view of foreign key
        /// </summary>        
        public virtual void SetFK_IdApplication(DBApplication paramIdApplication)
        {
          localIdApplication = paramIdApplication;
          IdApplication = paramIdApplication.IdApplication;
        }
      
        /// <summary>
        /// Getter method for Object encapsulated view of foreign key
        /// </summary>
        public virtual DBCustomer GetFK_IdCustomer()
        {
          return localIdCustomer ?? (localIdCustomer = DBCustomer.GetEntity(IdCustomer));
        }
        /// <summary>
        /// Setter method for Object encapsulated view of foreign key
        /// </summary>        
        public virtual void SetFK_IdCustomer(DBCustomer paramIdCustomer)
        {
          localIdCustomer = paramIdCustomer;
          IdCustomer = paramIdCustomer.IdCustomer;
        }
      
        #endregion Foreign Keys


		    protected override ValidationModelBase Validator
		    {
			    get { return new DBLicenseValidator(); }
		    }
		#endregion public properties
    
		#region enumerator

		/// <summary>
		/// This enumerator contains a list of all the fields of the datasource
		/// </summary>
		public enum FieldNames
		{
			IdLicense,
			IdApplication,
			IdCustomer,
			IdTransaction,
			LicenseType,
			LicenseStatus,
			LicenseData,
			LicenseExpiryDate,

		}

		#endregion enumerator
    
		#region generic field methods

		/// <summary>
		/// Validates if a given  field value is a DbNull
		/// </summary>
		/// <param name="fieldName">The field to validate</param>
		///<returns>true if is DbNull, false otherwise</returns>
		public bool IsDbNull(FieldNames fieldName)
		{
			switch (fieldName)
			{

				case FieldNames.IdLicense: return (foIdLicense.Value is DBNull);

				case FieldNames.IdApplication: return (foIdApplication.Value is DBNull);

				case FieldNames.IdCustomer: return (foIdCustomer.Value is DBNull);

				case FieldNames.IdTransaction: return (foIdTransaction.Value is DBNull);

				case FieldNames.LicenseType: return (foLicenseType.Value is DBNull);

				case FieldNames.LicenseStatus: return (foLicenseStatus.Value is DBNull);

				case FieldNames.LicenseData: return (foLicenseData.Value is DBNull);

				case FieldNames.LicenseExpiryDate: return (foLicenseExpiryDate.Value is DBNull);

			}

			throw new InvalidDataException();
		}

		/// <summary>
		/// Sets the given field value to DbNull
		/// </summary>
		/// <param name="fieldName">The field to set</param>
		public void SetDbNull(FieldNames fieldName)
		{
			switch (fieldName)
			{

				case FieldNames.IdLicense:
					foIdLicense.Value = DBNull.Value; break;

				case FieldNames.IdApplication:
					foIdApplication.Value = DBNull.Value; break;

				case FieldNames.IdCustomer:
					foIdCustomer.Value = DBNull.Value; break;

				case FieldNames.IdTransaction:
					foIdTransaction.Value = DBNull.Value; break;

				case FieldNames.LicenseType:
					foLicenseType.Value = DBNull.Value; break;

				case FieldNames.LicenseStatus:
					foLicenseStatus.Value = DBNull.Value; break;

				case FieldNames.LicenseData:
					foLicenseData.Value = DBNull.Value; break;

				case FieldNames.LicenseExpiryDate:
					foLicenseExpiryDate.Value = DBNull.Value; break;

			}
		}
		
		#endregion generic field methods
    
        #region static factories

		/// <summary>
		/// Creates a new DB object that can be added to the database as a new row
		/// </summary>
		/// <returns>The instance of the DB Object</returns>
		public static DBLicense NewRow
		{
			get { return new DBLicense(); }
		}

		/// <summary>
		/// Returns multiple rows from the Datasource by a given set of WHERE clause fields, only includes fields where value != null
		/// </summary>
		/// <example>List of fields to filter by, null to ignore field (null = all).</example>
		/// <returns>A collection with the filtered results. </returns>
		internal static IEnumerable<DBLicense> ListEntity(object foIdLicense, object foIdApplication, object foIdCustomer, object foIdTransaction, object foLicenseType, object foLicenseStatus, object foLicenseData, object foLicenseExpiryDate)
		{
			DBLicense helper = new DBLicense();
			

			helper.foIdLicense.Value = foIdLicense;

			helper.foIdApplication.Value = foIdApplication;

			helper.foIdCustomer.Value = foIdCustomer;

			helper.foIdTransaction.Value = foIdTransaction;

			helper.foLicenseType.Value = foLicenseType;

			helper.foLicenseStatus.Value = foLicenseStatus;

			helper.foLicenseData.Value = foLicenseData;

			helper.foLicenseExpiryDate.Value = foLicenseExpiryDate;


			return helper.GetEntityInstancesList(helper.Fields.ToArray()).Cast<DBLicense>();
        }

		/// <summary>
		/// Returns multiple rows from the Datasource by a given set of WHERE clause fields, only includes fields where value != null
		/// </summary>
		/// <example>List of fields to filter by, null to ignore field (null = all).</example>
		/// <returns>A collection with the filtered results. </returns>
		internal static IEnumerable<DBLicense> ListEntity()
		{
			return new DBLicense().GetEntityInstancesList(new DbField[0]).Cast<DBLicense>();
        }

      		/// <summary>
		/// Returns a single row from the datasource by a given set of RUID strong-typed values
		/// </summary>
		/// <returns>The instance for this key or a new one if no match is found.</returns>
		internal static DBLicense GetEntity(int foIdLicense)
		{
			DBLicense helper = new DBLicense();

			helper.foIdLicense.Value = foIdLicense;

			helper = helper.GetEntityInstance(helper.Ruid) as DBLicense;
			
			return helper;
		}


        /// <summary>
        /// Returns multiple rows from the Datasource that referentiate a specific foreign object 
        /// </summary>
        /// <param name="foIdApplication">The <see cref="DBApplication"/> object to filter by.</param>
        /// <returns>A collection with the filtered results.</returns>
        public static  IEnumerable<DBLicense> ListEntityIdApplication(DBApplication foIdApplication)
        {
          DBLicense helper = new DBLicense();

          helper.foIdApplication.Value = foIdApplication.IdApplication;

          return helper.GetEntityInstancesList(helper.foIdApplication).Cast<DBLicense>();
        }

        /// <summary>
        /// Returns multiple rows from the Datasource that referentiate a specific foreign object 
        /// </summary>
        /// <param name="foIdCustomer">The <see cref="DBCustomer"/> object to filter by.</param>
        /// <returns>A collection with the filtered results.</returns>
        public static  IEnumerable<DBLicense> ListEntityIdCustomer(DBCustomer foIdCustomer)
        {
          DBLicense helper = new DBLicense();

          helper.foIdCustomer.Value = foIdCustomer.IdCustomer;

          return helper.GetEntityInstancesList(helper.foIdCustomer).Cast<DBLicense>();
        }

		#endregion static factories
	}
}